class Solution
{
public:
    bool canChoose(vector<vector<int>> &groups, vector<int> &nums)
    {
        auto numPos = nums.begin();
        for (auto &group : groups)
        {
            bool canMatch = false;
            while (numPos != nums.end())
            {
                auto matchNumPos = numPos;
                auto groupPos = group.begin();
                while (matchNumPos != nums.end() && groupPos != group.end())
                {
                    if (*matchNumPos == *groupPos)
                    {
                        ++matchNumPos;
                        ++groupPos;
                    }
                    else
                    {
                        break;
                    }
                }
                if (groupPos == group.end())
                {
                    canMatch = true;
                    numPos = matchNumPos;
                    break;
                }
                else
                {
                    ++numPos;
                }
            }
            if (!canMatch)
            {
                return false;
            }
        }
        return true;
    }
};